<?php
function a2j($arr){
	$str='';
		foreach($arr as $key =>$value){
			$str.=$key.":'".$value."',";
			}
	return $str;
	}
function a2a($arr){
	$str='';
		foreach($arr as $key =>$value){
			$str.="['".$key."','".$value."'],";
			}
	return substr($str,0,-1);
	}

/*$arr=array(
	'name'=>'test',
	'v'=>'love',
	'lb'=>'测试',
	'et'=>'测试',
	'fw'=>'80',
	'lb'=>'测试',
	'iv'=>'10',
	'mv'=>'100',
	'id'=>'test',
	'ab'=>true
	);
echo a2j($arr);
*/

function F_textfield($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	echo preg_replace("/[\s]{2,}/","","{
		xtype: 'textfield',
		value:'".$arg['v']."',
        fieldLabel:'".$arg['lb']."',
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".(($arg['it'])?("inputType:'".$arg['it']."',"):(""))."
		".(($arg['vt'])?("vtype:'".$arg['vt']."',"):(""))."
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
        name: '".$arg['name']."'
        }");
		
	}
/*$arr=array(
	'name'=>'test',
	'v'=>'love',
	'lb'=>'测试',
	'id'=>'test',
	'a2j'=>array(
				 'q'=>'q',
				 'a'=>'q',
				 'b'=>'q',
				 'q'=>'q'
				 ),
	'ab'=>true
	);
F_textfield($arr);
*/
function F_numberfield($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	echo preg_replace("/[\s]{2,}/","","{
		xtype: 'numberfield',
		value:'".$arg['v']."',
        fieldLabel:'".$arg['lb']."',
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".(($arg['it'])?("inputType:'".$arg['it']."',"):(""))."
		".(($arg['vt'])?("vtype:'".$arg['vt']."',"):(""))."
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['fw'])?("fieldWidth:'".$arg['fw']."',"):(""))."
		".(($arg['iv'])?("minValue:'".$arg['iv']."',"):(""))."
		".(($arg['mv'])?("maxValue:'".$arg['mv']."',"):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
		".(($arg['rd'])?("renderer:".$arg['rd'].","):(""))."
        name: '".$arg['name']."'
        }");
		
	}
/*$arr=array(
	'name'=>'test',
	'v'=>'love',
	'lb'=>'测试',
	'et'=>'测试',
	'fw'=>'80',
	'lb'=>'测试',
	'iv'=>'10',
	'mv'=>'100',
	'str'=>"ab:'1',cd:3:bad'15'",
	'a2j'=>array('a'=>"b","c"=>'d','iv'=>10),
	'id'=>'test',
	'ab'=>true
	);
F_NumberField($arr);
*/
function F_combo($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	echo preg_replace("/[\s]{2,}/","","{
		xtype: 'combo',
		value:'".$arg['v']."',
        fieldLabel:'".$arg['lb']."',
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
		".(($arg['rd'])?("renderer:".$arg['rd'].","):(""))."
		   valueField :'yinv',   
		   displayField:'xianv',   
		store:new Ext.data.SimpleStore({
						fields:['yinv','xianv'],
						data:[".a2a($arg['data'])."]}),
        hiddenName: '".$arg['name']."'
        }");
		
	}
	
function F_radio($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	$str='';
	foreach($arg['data'] as $key =>$value){
			$str.="{boxLabel: '".$value."', name: '".$arg['name']."',inputValue:'".$key."'".(($key==$arg['checked'])?(" , checked: true"):(""))."},";
			}
	$str=substr($str,0,-1);
	
	echo preg_replace("/[\s]{2,}/","","	{
                xtype: 'radiogroup',
 		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
		".(($arg['rd'])?("renderer:".$arg['rd'].","):(""))."
               items: [".$str."                   
	                ],
			fieldLabel:'".$arg['lb']."'
            }");
		
	}
	
function F_checkbox($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	$str='';
	foreach($arg['data'] as $key =>$value){
			$str.="{boxLabel: '".$value."', name: '".$arg['name']."[".$key."]',inputValue:'".$key."'".((in_array($key,$arg['checked']))?(" , checked: true"):(""))."},";
			}
	$str=substr($str,0,-1);
	
	echo preg_replace("/[\s]{2,}/","","	{
                xtype: 'checkboxgroup',
 		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
		".(($arg['rd'])?("renderer:".$arg['rd'].","):(""))."
               items: [".$str."                   
	                ],
			fieldLabel:'".$arg['lb']."'
            }");
		
	}
function F_datefield($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	echo preg_replace("/[\s]{2,}/","","{
		xtype: 'datefield',
		value:'".$arg['v']."',
        fieldLabel:'".$arg['lb']."',
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
        name: '".$arg['name']."'
        }");
		
	}
function F_timefield($arr){
	$arg=func_get_args();
//	print_r($arg);
	$arg=$arg[0];
	echo preg_replace("/[\s]{2,}/","","{
		xtype: 'timefield',
		value:'".$arg['v']."',
        fieldLabel:'".$arg['lb']."',
		".(($arg['id'])?("id:'".$arg['id']."',"):(""))."
		".(($arg['bt'])?("blankText:'".$arg['bt']."',"):(""))."
		".(($arg['et'])?("emptyText:'".$arg['et']."',"):(""))."
		".(($arg['ab'])?("allowBlank:".$arg['ab'].","):(""))."
		".a2j($arg['a2j'])."
		".$arg['str']."
        name: '".$arg['name']."'
        }");
		
	}

function combozy($value,$arr){
	return $arr['data'][$value]?$arr['data'][$value]:$value;
	}

function sczd($config,$zd,$value){
		$zdcfg=$config[$zd];
		$zdcfg['v']=$value;
		$fstr='F_'.$config[$zd]['xtype'];
		$fstr($zdcfg);
	}	
/*$jcfg=array(
			'id'=>array(
						'xtype'=>'textfield',
						'name'=>'id',
						'a2j'=>array(
									 ),
						'str'=>"readOnly:true,",
						'lb'=>'ID'
						)
			);
sczd($jcfg,'id','23');
*/?>
